//
//  ZNWBNavigationController.swift
//  ZNWeibo
//
//  Created by FunctionMaker on 2017/7/28.
//  Copyright © 2017年 FunctionMaker. All rights reserved.
//

import UIKit

class ZNWBNavigationController: UINavigationController/*, UIGestureRecognizerDelegate*/ {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //隐藏默认的导航栏
        navigationBar.isHidden = true
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        //当控制器不是当前导航控制器的根控制器时，才隐藏tabBar
        if childViewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            
            if let viewController = viewController as? ZNWBBaseViewController {
                var title = "返回"
                
                if childViewControllers.count == 1 {
                    title = childViewControllers.first?.title ?? title
                }
                
                viewController.zn_navigationItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToBeforeViewController), event: .touchUpInside, isBack: true)
            }
        }
        
        super.pushViewController(viewController, animated: animated)
        //此方法将导致底部标签栏不在出现
//        self.interactivePopGestureRecognizer?.delegate = self
    }
    
    @objc private func popToBeforeViewController() {
        popViewController(animated: true)
    }
    
//    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
//        return self.childViewControllers.count > 1
//    }
}
